<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>JavaScript常用API合集 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="JavaScript,API,">
  

  <meta name="description" content="来源于互联网  一、节点1.1 节点属性 Node.nodeName   //返回节点名称，只读Node.nodeType   //返回节点类型的常数值，只读Node.nodeValue  //返回Text或Comment节点的文本值，只读Node.textContent  //返回当前节点和它的所有后代节点的文本内容，可读写Node.baseURI    //返回当前网页的绝对路径Node.o">
<meta name="keywords" content="JavaScript,API">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript常用API合集">
<meta property="og:url" content="http://blog.poetries.top/2017/12/24/js-api/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="来源于互联网  一、节点1.1 节点属性 Node.nodeName   //返回节点名称，只读Node.nodeType   //返回节点类型的常数值，只读Node.nodeValue  //返回Text或Comment节点的文本值，只读Node.textContent  //返回当前节点和它的所有后代节点的文本内容，可读写Node.baseURI    //返回当前网页的绝对路径Node.o">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-08-15T04:25:31.926Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JavaScript常用API合集">
<meta name="twitter:description" content="来源于互联网  一、节点1.1 节点属性 Node.nodeName   //返回节点名称，只读Node.nodeType   //返回节点类型的常数值，只读Node.nodeValue  //返回Text或Comment节点的文本值，只读Node.textContent  //返回当前节点和它的所有后代节点的文本内容，可读写Node.baseURI    //返回当前网页的绝对路径Node.o">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、节点"><span class="toc-text">一、节点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、CSS操作"><span class="toc-text">二、CSS操作</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、对象"><span class="toc-text">三、对象</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-js-api" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">JavaScript常用API合集</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2017.12.24</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 6k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 22分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <blockquote>
<p>来源于互联网</p>
</blockquote>
<h2 id="一、节点"><a href="#一、节点" class="headerlink" title="一、节点"></a>一、节点</h2><p><strong>1.1 节点属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Node.nodeName   <span class="comment">//返回节点名称，只读</span></span><br><span class="line">Node.nodeType   <span class="comment">//返回节点类型的常数值，只读</span></span><br><span class="line">Node.nodeValue  <span class="comment">//返回Text或Comment节点的文本值，只读</span></span><br><span class="line">Node.textContent  <span class="comment">//返回当前节点和它的所有后代节点的文本内容，可读写</span></span><br><span class="line">Node.baseURI    <span class="comment">//返回当前网页的绝对路径</span></span><br><span class="line"></span><br><span class="line">Node.ownerDocument  <span class="comment">//返回当前节点所在的顶层文档对象，即document</span></span><br><span class="line">Node.nextSibling  <span class="comment">//返回紧跟在当前节点后面的第一个兄弟节点</span></span><br><span class="line">Node.previousSibling  <span class="comment">//返回当前节点前面的、距离最近的一个兄弟节点</span></span><br><span class="line">Node.parentNode   <span class="comment">//返回当前节点的父节点</span></span><br><span class="line">Node.parentElement  <span class="comment">//返回当前节点的父Element节点</span></span><br><span class="line">Node.childNodes   <span class="comment">//返回当前节点的所有子节点</span></span><br><span class="line">Node.firstChild  <span class="comment">//返回当前节点的第一个子节点</span></span><br><span class="line">Node.lastChild   <span class="comment">//返回当前节点的最后一个子节点</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//parentNode接口</span></span><br><span class="line">Node.children  <span class="comment">//返回指定节点的所有Element子节点</span></span><br><span class="line">Node.firstElementChild  <span class="comment">//返回当前节点的第一个Element子节点</span></span><br><span class="line">Node.lastElementChild   <span class="comment">//返回当前节点的最后一个Element子节点</span></span><br><span class="line">Node.childElementCount  <span class="comment">//返回当前节点所有Element子节点的数目。</span></span><br></pre></td></tr></table></figure>
<p><strong>1.2 操作</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Node.appendChild(node)   <span class="comment">//向节点添加最后一个子节点</span></span><br><span class="line">Node.hasChildNodes()   <span class="comment">//返回布尔值，表示当前节点是否有子节点</span></span><br><span class="line">Node.cloneNode(<span class="literal">true</span>);  <span class="comment">// 默认为false(克隆节点), true(克隆节点及其属性，以及后代)</span></span><br><span class="line">Node.insertBefore(newNode,oldNode)  <span class="comment">// 在指定子节点之前插入新的子节点</span></span><br><span class="line">Node.removeChild(node)   <span class="comment">//删除节点，在要删除节点的父节点上操作</span></span><br><span class="line">Node.replaceChild(newChild,oldChild)  <span class="comment">//替换节点</span></span><br><span class="line">Node.contains(node)  <span class="comment">//返回一个布尔值，表示参数节点是否为当前节点的后代节点。</span></span><br><span class="line">Node.compareDocumentPosition(node)   <span class="comment">//返回一个7个比特位的二进制值，表示参数节点和当前节点的关系</span></span><br><span class="line">Node.isEqualNode(noe)  <span class="comment">//返回布尔值，用于检查两个节点是否相等。所谓相等的节点，指的是两个节点的类型相同、属性相同、子节点相同。</span></span><br><span class="line">Node.normalize()   <span class="comment">//用于清理当前节点内部的所有Text节点。它会去除空的文本节点，并且将毗邻的文本节点合并成一个。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//ChildNode接口</span></span><br><span class="line">Node.remove()  <span class="comment">//用于删除当前节点</span></span><br><span class="line">Node.before()  <span class="comment">//</span></span><br><span class="line">Node.after()</span><br><span class="line">Node.replaceWith()</span><br></pre></td></tr></table></figure>
<p><strong>1.3 Document节点</strong></p>
<p><strong>1.3.1 Document节点的属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">document</span>.doctype   <span class="comment">//</span></span><br><span class="line"><span class="built_in">document</span>.documentElement  <span class="comment">//返回当前文档的根节点</span></span><br><span class="line"><span class="built_in">document</span>.defaultView   <span class="comment">//返回document对象所在的window对象</span></span><br><span class="line"><span class="built_in">document</span>.body   <span class="comment">//返回当前文档的&lt;body&gt;节点</span></span><br><span class="line"><span class="built_in">document</span>.head   <span class="comment">//返回当前文档的&lt;head&gt;节点</span></span><br><span class="line"><span class="built_in">document</span>.activeElement  <span class="comment">//返回当前文档中获得焦点的那个元素。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//节点集合属性</span></span><br><span class="line"><span class="built_in">document</span>.links  <span class="comment">//返回当前文档的所有a元素</span></span><br><span class="line"><span class="built_in">document</span>.forms  <span class="comment">//返回页面中所有表单元素</span></span><br><span class="line"><span class="built_in">document</span>.images  <span class="comment">//返回页面中所有图片元素</span></span><br><span class="line"><span class="built_in">document</span>.embeds  <span class="comment">//返回网页中所有嵌入对象</span></span><br><span class="line"><span class="built_in">document</span>.scripts  <span class="comment">//返回当前文档的所有脚本</span></span><br><span class="line"><span class="built_in">document</span>.styleSheets  <span class="comment">//返回当前网页的所有样式表</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//文档信息属性</span></span><br><span class="line"><span class="built_in">document</span>.documentURI  <span class="comment">//表示当前文档的网址</span></span><br><span class="line"><span class="built_in">document</span>.URL  <span class="comment">//返回当前文档的网址</span></span><br><span class="line"><span class="built_in">document</span>.domain  <span class="comment">//返回当前文档的域名</span></span><br><span class="line"><span class="built_in">document</span>.lastModified  <span class="comment">//返回当前文档最后修改的时间戳</span></span><br><span class="line"><span class="built_in">document</span>.location  <span class="comment">//返回location对象，提供当前文档的URL信息</span></span><br><span class="line"><span class="built_in">document</span>.referrer  <span class="comment">//返回当前文档的访问来源</span></span><br><span class="line"><span class="built_in">document</span>.title    <span class="comment">//返回当前文档的标题</span></span><br><span class="line"><span class="built_in">document</span>.characterSet属性返回渲染当前文档的字符集，比如UTF<span class="number">-8</span>、ISO<span class="number">-8859</span><span class="number">-1</span>。</span><br><span class="line"><span class="built_in">document</span>.readyState  <span class="comment">//返回当前文档的状态</span></span><br><span class="line"><span class="built_in">document</span>.designMode  <span class="comment">//控制当前文档是否可编辑，可读写</span></span><br><span class="line"><span class="built_in">document</span>.compatMode  <span class="comment">//返回浏览器处理文档的模式</span></span><br><span class="line"><span class="built_in">document</span>.cookie   <span class="comment">//用来操作Cookie</span></span><br></pre></td></tr></table></figure>
<p><strong>1.3.2 Document节点的方法</strong></p>
<p><strong>（1）读写方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">document</span>.open()   <span class="comment">//用于新建并打开一个文档</span></span><br><span class="line"><span class="built_in">document</span>.close()   <span class="comment">//不安比open方法所新建的文档</span></span><br><span class="line"><span class="built_in">document</span>.write()   <span class="comment">//用于向当前文档写入内容</span></span><br><span class="line"><span class="built_in">document</span>.writeIn()  <span class="comment">//用于向当前文档写入内容，尾部添加换行符。</span></span><br></pre></td></tr></table></figure>
<p><strong>（2）查找节点</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">document</span>.querySelector(selectors)   <span class="comment">//接受一个CSS选择器作为参数，返回第一个匹配该选择器的元素节点。</span></span><br><span class="line"><span class="built_in">document</span>.querySelectorAll(selectors)  <span class="comment">//接受一个CSS选择器作为参数，返回所有匹配该选择器的元素节点。</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByTagName(tagName)  <span class="comment">//返回所有指定HTML标签的元素</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByClassName(className)   <span class="comment">//返回包括了所有class名字符合指定条件的元素</span></span><br><span class="line"><span class="built_in">document</span>.getElementsByName(name)   <span class="comment">//用于选择拥有name属性的HTML元素（比如&lt;form&gt;、&lt;radio&gt;、&lt;img&gt;、&lt;frame&gt;、&lt;embed&gt;和&lt;object&gt;等）</span></span><br><span class="line"><span class="built_in">document</span>.getElementById(id)   <span class="comment">//返回匹配指定id属性的元素节点。</span></span><br><span class="line"><span class="built_in">document</span>.elementFromPoint(x,y)  <span class="comment">//返回位于页面指定位置最上层的Element子节点。</span></span><br></pre></td></tr></table></figure>
<p><strong>（3）生成节点</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">document</span>.createElement(tagName)   <span class="comment">//用来生成HTML元素节点。</span></span><br><span class="line"><span class="built_in">document</span>.createTextNode(text)   <span class="comment">//用来生成文本节点</span></span><br><span class="line"><span class="built_in">document</span>.createAttribute(name)  <span class="comment">//生成一个新的属性对象节点，并返回它。</span></span><br><span class="line"><span class="built_in">document</span>.createDocumentFragment()  <span class="comment">//生成一个DocumentFragment对象</span></span><br></pre></td></tr></table></figure>
<p><strong>（4）事件方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">document</span>.createEvent(type)   <span class="comment">//生成一个事件对象，该对象能被element.dispatchEvent()方法使用</span></span><br><span class="line"><span class="built_in">document</span>.addEventListener(type,listener,capture)  <span class="comment">//注册事件</span></span><br><span class="line"><span class="built_in">document</span>.removeEventListener(type,listener,capture)  <span class="comment">//注销事件</span></span><br><span class="line"><span class="built_in">document</span>.dispatchEvent(event)  <span class="comment">//触发事件</span></span><br></pre></td></tr></table></figure>
<p><strong>（5）其他</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">document.hasFocus()   //返回一个布尔值，表示当前文档之中是否有元素被激活或获得焦点。</span><br><span class="line">document.adoptNode(externalNode)  //将某个节点，从其原来所在的文档移除，插入当前文档，并返回插入后的新节点。</span><br><span class="line">document.importNode(externalNode, deep)   //从外部文档拷贝指定节点，插入当前文档。</span><br></pre></td></tr></table></figure>
<p><strong>1.4 Element节点</strong></p>
<p><strong>1.4.1 Element节点的属性</strong></p>
<p><strong>（1）特性属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.attributes  <span class="comment">//返回当前元素节点的所有属性节点</span></span><br><span class="line">Element.id  <span class="comment">//返回指定元素的id属性，可读写</span></span><br><span class="line">Element.tagName  <span class="comment">//返回指定元素的大写标签名</span></span><br><span class="line">Element.innerHTML   <span class="comment">//返回该元素包含的HTML代码，可读写</span></span><br><span class="line">Element.outerHTML  <span class="comment">//返回指定元素节点的所有HTML代码，包括它自身和包含的的所有子元素，可读写</span></span><br><span class="line">Element.className  <span class="comment">//返回当前元素的class属性，可读写</span></span><br><span class="line">Element.classList  <span class="comment">//返回当前元素节点的所有class集合</span></span><br><span class="line">Element.dataset   <span class="comment">//返回元素节点中所有的data-*属性。</span></span><br></pre></td></tr></table></figure>
<p><strong>（2）尺寸属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.clientHeight   <span class="comment">//返回元素节点可见部分的高度</span></span><br><span class="line">Element.clientWidth   <span class="comment">//返回元素节点可见部分的宽度</span></span><br><span class="line">Element.clientLeft   <span class="comment">//返回元素节点左边框的宽度</span></span><br><span class="line">Element.clientTop   <span class="comment">//返回元素节点顶部边框的宽度</span></span><br><span class="line">Element.scrollHeight  <span class="comment">//返回元素节点的总高度</span></span><br><span class="line">Element.scrollWidth  <span class="comment">//返回元素节点的总宽度</span></span><br><span class="line">Element.scrollLeft   <span class="comment">//返回元素节点的水平滚动条向右滚动的像素数值,通过设置这个属性可以改变元素的滚动位置</span></span><br><span class="line">Element.scrollTop   <span class="comment">//返回元素节点的垂直滚动向下滚动的像素数值</span></span><br><span class="line">Element.offsetHeight   <span class="comment">//返回元素的垂直高度(包含border,padding)</span></span><br><span class="line">Element.offsetWidth    <span class="comment">//返回元素的水平宽度(包含border,padding)</span></span><br><span class="line">Element.offsetLeft    <span class="comment">//返回当前元素左上角相对于Element.offsetParent节点的垂直偏移</span></span><br><span class="line">Element.offsetTop   <span class="comment">//返回水平位移</span></span><br><span class="line">Element.style  <span class="comment">//返回元素节点的行内样式</span></span><br></pre></td></tr></table></figure>
<p><strong>（3）节点相关属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.children   <span class="comment">//包括当前元素节点的所有子元素</span></span><br><span class="line">Element.childElementCount   <span class="comment">//返回当前元素节点包含的子HTML元素节点的个数</span></span><br><span class="line">Element.firstElementChild  <span class="comment">//返回当前节点的第一个Element子节点  </span></span><br><span class="line">Element.lastElementChild   <span class="comment">//返回当前节点的最后一个Element子节点  </span></span><br><span class="line">Element.nextElementSibling  <span class="comment">//返回当前元素节点的下一个兄弟HTML元素节点</span></span><br><span class="line">Element.previousElementSibling  <span class="comment">//返回当前元素节点的前一个兄弟HTML节点</span></span><br><span class="line">Element.offsetParent   <span class="comment">//返回当前元素节点的最靠近的、并且CSS的position属性不等于static的父元素。</span></span><br></pre></td></tr></table></figure>
<p><strong>1.4.2 Element节点的方法</strong></p>
<p><strong>（1）位置方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">getBoundingClientRect()  </span><br><span class="line"><span class="comment">// getBoundingClientRect返回一个对象，包含top,left,right,bottom,width,height // width、height 元素自身宽高</span></span><br><span class="line"><span class="comment">// top 元素上外边界距窗口最上面的距离</span></span><br><span class="line"><span class="comment">// right 元素右外边界距窗口最上面的距离</span></span><br><span class="line"><span class="comment">// bottom 元素下外边界距窗口最上面的距离</span></span><br><span class="line"><span class="comment">// left 元素左外边界距窗口最上面的距离</span></span><br><span class="line"><span class="comment">// width 元素自身宽(包含border,padding) </span></span><br><span class="line"><span class="comment">// height 元素自身高(包含border,padding) </span></span><br><span class="line"></span><br><span class="line">getClientRects()   <span class="comment">//返回当前元素在页面上形参的所有矩形。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 元素在页面上的偏移量  </span></span><br><span class="line"><span class="keyword">var</span> rect = el.getBoundingClientRect()  </span><br><span class="line"><span class="keyword">return</span> &#123;   </span><br><span class="line">  top: rect.top + <span class="built_in">document</span>.body.scrollTop,   </span><br><span class="line">  left: rect.left + <span class="built_in">document</span>.body.scrollLeft  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>（2）属性方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.getAttribute()：读取指定属性  </span><br><span class="line">Element.setAttribute()：设置指定属性  </span><br><span class="line">Element.hasAttribute()：返回一个布尔值，表示当前元素节点是否有指定的属性  </span><br><span class="line">Element.removeAttribute()：移除指定属性</span><br></pre></td></tr></table></figure>
<p><strong>（3）查找方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.querySelector()  </span><br><span class="line">Element.querySelectorAll()  </span><br><span class="line">Element.getElementsByTagName()  </span><br><span class="line">Element.getElementsByClassName()</span><br></pre></td></tr></table></figure>
<p><strong>（4）事件方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.addEventListener()：添加事件的回调函数  </span><br><span class="line">Element.removeEventListener()：移除事件监听函数  </span><br><span class="line">Element.dispatchEvent()：触发事件</span><br><span class="line"></span><br><span class="line"><span class="comment">//ie8</span></span><br><span class="line">Element.attachEvent(oneventName,listener)</span><br><span class="line">Element.detachEvent(oneventName,listener)</span><br><span class="line"></span><br><span class="line"><span class="comment">// event对象  </span></span><br><span class="line"><span class="keyword">var</span> event = <span class="built_in">window</span>.event||event;    </span><br><span class="line"></span><br><span class="line"><span class="comment">// 事件的目标节点  </span></span><br><span class="line"><span class="keyword">var</span> target = event.target || event.srcElement;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 事件代理  </span></span><br><span class="line">ul.addEventListener(<span class="string">'click'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>&#123;   </span><br><span class="line">  <span class="keyword">if</span> (event.target.tagName.toLowerCase() === <span class="string">'li'</span>) &#123;   </span><br><span class="line">    <span class="built_in">console</span>.log(event.target.innerHTML)   </span><br><span class="line">  &#125;  </span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p><strong>（5）其他</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">Element.scrollIntoView()   <span class="comment">//滚动当前元素，进入浏览器的可见区域</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//解析HTML字符串，然后将生成的节点插入DOM树的指定位置。</span></span><br><span class="line">Element.insertAdjacentHTML(where, htmlString); </span><br><span class="line">Element.insertAdjacentHTML(<span class="string">'beforeBegin'</span>, htmlString); <span class="comment">// 在该元素前插入  </span></span><br><span class="line">Element.insertAdjacentHTML(<span class="string">'afterBegin'</span>, htmlString); <span class="comment">// 在该元素第一个子元素前插入 </span></span><br><span class="line">Element.insertAdjacentHTML(<span class="string">'beforeEnd'</span>, htmlString); <span class="comment">// 在该元素最后一个子元素后面插入 </span></span><br><span class="line">Element.insertAdjacentHTML(<span class="string">'afterEnd'</span>, htmlString); <span class="comment">// 在该元素后插入</span></span><br><span class="line"></span><br><span class="line">Element.remove()  <span class="comment">//用于将当前元素节点从DOM中移除</span></span><br><span class="line">Element.focus()   <span class="comment">//用于将当前页面的焦点，转移到指定元素上</span></span><br></pre></td></tr></table></figure>
<h2 id="二、CSS操作"><a href="#二、CSS操作" class="headerlink" title="二、CSS操作"></a>二、CSS操作</h2><p><strong>（1）类名操作</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//ie8以下</span></span><br><span class="line">Element.className  <span class="comment">//获取元素节点的类名</span></span><br><span class="line">Element.className += <span class="string">' '</span> + newClassName  <span class="comment">//新增一个类名</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//判断是否有某个类名</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">hasClass</span>(<span class="params">element,className</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">RegExp</span>(className,<span class="string">'gi'</span>).test(element.className);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//移除class</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">removeClass</span>(<span class="params">element,className</span>)</span>&#123;</span><br><span class="line">  element.className = element.className.replace(<span class="keyword">new</span> <span class="built_in">RegExp</span>(<span class="string">'(^|\\b)'</span> + className.split(<span class="string">' '</span>).join(<span class="string">'|'</span>) + <span class="string">'(\\b|$)'</span>, <span class="string">'gi'</span>),<span class="string">''</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//ie10 </span></span><br><span class="line">element.classList.add(className)  <span class="comment">//新增</span></span><br><span class="line">element.classList.remove(className)  <span class="comment">//删除</span></span><br><span class="line">element.classList.contains(className)  <span class="comment">//是否包含</span></span><br><span class="line">element.classList.toggle(className)  <span class="comment">//toggle class</span></span><br></pre></td></tr></table></figure>
<p><strong>（2）style操作</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">element.setAttribute(<span class="string">'style'</span>,<span class="string">''</span>)</span><br><span class="line"></span><br><span class="line">element.style.backgroundColor = <span class="string">'red'</span></span><br><span class="line"></span><br><span class="line">element.style.cssText <span class="comment">//用来读写或删除整个style属性</span></span><br><span class="line"></span><br><span class="line">element.style.setProperty(propertyName,value)  <span class="comment">//设置css属性</span></span><br><span class="line">element.style.getPropertyValue(property)  <span class="comment">//获取css属性</span></span><br><span class="line">element.style.removeProperty(property)  <span class="comment">//删除css属性</span></span><br><span class="line">操作非内联样式</span><br><span class="line"><span class="comment">//ie8</span></span><br><span class="line">element.currentStyle[attrName]</span><br><span class="line"><span class="comment">//ie9+</span></span><br><span class="line"><span class="built_in">window</span>.getComputedStyle(el,<span class="literal">null</span>)[attrName] </span><br><span class="line"><span class="built_in">window</span>.getComputedStyle(el,<span class="literal">null</span>).getPropertyValue(attrName)</span><br><span class="line"><span class="comment">//伪类</span></span><br><span class="line"><span class="built_in">window</span>.getComputedStyle(el,<span class="string">':after'</span>)[attrName]</span><br></pre></td></tr></table></figure>
<h2 id="三、对象"><a href="#三、对象" class="headerlink" title="三、对象"></a>三、对象</h2><p><strong>3.1 Object对象</strong></p>
<p><strong>（1）生成实例对象</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> o = <span class="keyword">new</span> <span class="built_in">Object</span>()</span><br></pre></td></tr></table></figure>
<p><strong>（2）属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Object</span>.prototype   <span class="comment">//返回原型对象</span></span><br></pre></td></tr></table></figure>
<p><strong>（3）方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Object</span>.keys(o)   <span class="comment">//遍历对象的可枚举属性</span></span><br><span class="line"><span class="built_in">Object</span>.getOwnPropertyName(o)   <span class="comment">//遍历对象不可枚举的属性</span></span><br></pre></td></tr></table></figure>
<p><strong>对象实例的方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">valueOf()：返回当前对象对应的值。  </span><br><span class="line">toString()：返回当前对象对应的字符串形式。  </span><br><span class="line">toLocaleString()：返回当前对象对应的本地字符串形式。  </span><br><span class="line">hasOwnProperty()：判断某个属性是否为当前对象自身的属性，还是继承自原型对象的属性。 </span><br><span class="line">isPrototypeOf()：判断当前对象是否为另一个对象的原型。</span><br><span class="line">propertyIsEnumerable()：判断某个属性是否可枚举。</span><br></pre></td></tr></table></figure>
<p><strong>3.2 Array对象</strong></p>
<p><strong>（1）生成实例对象</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="built_in">Array</span>()</span><br></pre></td></tr></table></figure>
<p><strong>（2）属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">a.length  <span class="comment">//长度</span></span><br></pre></td></tr></table></figure>
<p><strong>（3）Array.isArray()</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Array</span>.isArray(a)   <span class="comment">//用来判断一个值是否为数组</span></span><br></pre></td></tr></table></figure>
<p><strong>（4）Array实例的方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">a.valueof()   <span class="comment">//返回数组本身</span></span><br><span class="line">a.toString()  <span class="comment">//返回数组的字符串形式</span></span><br><span class="line">a.push(value,vlaue....)   <span class="comment">//用于在数组的末端添加一个或多个元素，并返回添加新元素后的数组长度。</span></span><br><span class="line">pop()   <span class="comment">//用于删除数组的最后一个元素，并返回该元素</span></span><br><span class="line">join()  <span class="comment">//以参数作为分隔符，将所有数组成员组成一个字符串返回。如果不提供参数，默认用逗号分隔。</span></span><br><span class="line">concat()  <span class="comment">//用于多个数组的合并。它将新数组的成员，添加到原数组的尾部，然后返回一个新数组，原数组不变。</span></span><br><span class="line">shift()  <span class="comment">//用于删除数组的第一个元素，并返回该元素。</span></span><br><span class="line">unshift(value)  <span class="comment">//用于在数组的第一个位置添加元素，并返回添加新元素后的数组长度。</span></span><br><span class="line">reverse()   <span class="comment">//用于颠倒数组中元素的顺序，返回改变后的数组</span></span><br><span class="line">slice(start_index, upto_index);   <span class="comment">//用于提取原数组的一部分，返回一个新数组，原数组不变。第一个参数为起始位置（从0开始），第二个参数为终止位置（但该位置的元素本身不包括在内）。如果省略第二个参数，则一直返回到原数组的最后一个成员。负数表示倒数第几个。</span></span><br><span class="line">splice(index, count_to_remove, addElement1, addElement2, ...);   <span class="comment">//用于删除原数组的一部分成员，并可以在被删除的位置添加入新的数组成员，返回值是被删除的元素。第一个参数是删除的起始位置，第二个参数是被删除的元素个数。如果后面还有更多的参数，则表示这些就是要被插入数组的新元素。</span></span><br><span class="line">sort()   <span class="comment">//对数组成员进行排序，默认是按照字典顺序排序。排序后，原数组将被改变。如果想让sort方法按照自定义方式排序，可以传入一个函数作为参数，表示按照自定义方法进行排序。该函数本身又接受两个参数，表示进行比较的两个元素。如果返回值大于0，表示第一个元素排在第二个元素后面；其他情况下，都是第一个元素排在第二个元素前面。</span></span><br><span class="line">map()   <span class="comment">//对数组的所有成员依次调用一个函数，根据函数结果返回一个新数组。</span></span><br><span class="line">map(elem,index,arr)   <span class="comment">//map方法接受一个函数作为参数。该函数调用时，map方法会将其传入三个参数，分别是当前成员、当前位置和数组本身。</span></span><br><span class="line">forEach()   <span class="comment">//遍历数组的所有成员，执行某种操作,参数是一个函数。它接受三个参数，分别是当前位置的值、当前位置的编号和整个数组。</span></span><br><span class="line">filter()   <span class="comment">//参数是一个函数，所有数组成员依次执行该函数，返回结果为true的成员组成一个新数组返回。该方法不会改变原数组。</span></span><br><span class="line">some()    <span class="comment">//用来判断数组成员是否符合某种条件。接受一个函数作为参数，所有数组成员依次执行该函数，返回一个布尔值。该函数接受三个参数，依次是当前位置的成员、当前位置的序号和整个数组。只要有一个数组成员的返回值是true，则整个some方法的返回值就是true，否则false。</span></span><br><span class="line">every()   <span class="comment">//用来判断数组成员是否符合某种条件。接受一个函数作为参数，所有数组成员依次执行该函数，返回一个布尔值。该函数接受三个参数，依次是当前位置的成员、当前位置的序号和整个数组。所有数组成员的返回值都是true，才返回true，否则false。</span></span><br><span class="line">reduce()   <span class="comment">//依次处理数组的每个成员，最终累计为一个值。从左到右处理（从第一个成员到最后一个成员）</span></span><br><span class="line">reduceRight()  <span class="comment">//依次处理数组的每个成员，最终累计为一个值。从右到左（从最后一个成员到第一个成员）</span></span><br><span class="line">indexOf(s)   <span class="comment">//返回给定元素在数组中第一次出现的位置，如果没有出现则返回-1。可以接受第二个参数，表示搜索的开始位置</span></span><br><span class="line">lastIndexOf()  <span class="comment">//返回给定元素在数组中最后一次出现的位置，如果没有出现则返回-1。</span></span><br></pre></td></tr></table></figure>
<p><strong>3.3 Number对象</strong></p>
<p><strong>（1）生成对象</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> n = <span class="keyword">new</span> <span class="built_in">Number</span>()</span><br></pre></td></tr></table></figure>
<p><strong>（2）Number对象的属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Number</span>.POSITIVE_INFINITY：正的无限，指向<span class="literal">Infinity</span>。  </span><br><span class="line"><span class="built_in">Number</span>.NEGATIVE_INFINITY：负的无限，指向-<span class="literal">Infinity</span>。  </span><br><span class="line"><span class="built_in">Number</span>.NaN：表示非数值，指向<span class="literal">NaN</span>。  </span><br><span class="line"><span class="built_in">Number</span>.MAX_VALUE：表示最大的正数，相应的，最小的负数为-<span class="built_in">Number</span>.MAX_VALUE。  </span><br><span class="line"><span class="built_in">Number</span>.MIN_VALUE：表示最小的正数（即最接近<span class="number">0</span>的正数，在<span class="number">64</span>位浮点数体系中为<span class="number">5e-324</span>），相应的，最接近<span class="number">0</span>的负数为-<span class="built_in">Number</span>.MIN_VALUE。  </span><br><span class="line"><span class="built_in">Number</span>.MAX_SAFE_INTEGER：表示能够精确表示的最大整数，即<span class="number">9007199254740991</span>。  </span><br><span class="line"><span class="built_in">Number</span>.MIN_SAFE_INTEGER：表示能够精确表示的最小整数，即<span class="number">-9007199254740991</span>。</span><br></pre></td></tr></table></figure>
<p><strong>（4）Number对象实例的方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">toString()   <span class="comment">//用来将一个数值转为字符串形式.可以接受一个参数，表示输出的进制。如果省略这个参数，默认将数值先转为十进制，再输出字符串；否则，就根据参数指定的进制，将一个数字转化成某个进制的字符串。</span></span><br><span class="line">toFixed()   <span class="comment">//用于将一个数转为指定位数的小数，返回这个小数对应的字符串。</span></span><br><span class="line">toExponential()  <span class="comment">//用于将一个数转为科学计数法形式。可传入一个参数，参数表示小数点后有效数字的位数，范围为0到20，超出这个范围，会抛出一个RangeError。</span></span><br><span class="line">toPrecision()  <span class="comment">//用于将一个数转为指定位数的有效数字。</span></span><br></pre></td></tr></table></figure>
<p><strong>3.4 String 对象</strong></p>
<p><strong>（1）生成实例对象</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> s = <span class="keyword">new</span> <span class="built_in">String</span>()</span><br></pre></td></tr></table></figure>
<p><strong>（2）String对象的属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">s.length   <span class="comment">//返回字符串的长度</span></span><br></pre></td></tr></table></figure>
<p><strong>（3）方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">s.chatAt(index)   <span class="comment">//返回指定位置的字符</span></span><br><span class="line">s.fromCharCode()    <span class="comment">//该方法的参数是一系列Unicode码点，返回对应的字符串。</span></span><br><span class="line">s.charCodeAt(index)    <span class="comment">//返回给定位置字符的Unicode码点（十进制表示）</span></span><br><span class="line">s.concat(s2)  <span class="comment">//用于连接两个字符串</span></span><br><span class="line">s.slice(start,end)   <span class="comment">//用于从原字符串取出子字符串并返回，不改变原字符串。第一个参数是子字符串的开始位置，第二个参数是子字符串的结束位置（不含该位置）。如果参数是负值，表示从结尾开始倒数计算的位置，即该负值加上字符串长度。</span></span><br><span class="line">s.substring(start,end)  <span class="comment">//用于从原字符串取出子字符串并返回，不改变原字符串.第一个参数表示子字符串的开始位置，第二个位置表示结束位置。</span></span><br><span class="line">s.substr(start,length)   <span class="comment">//用于从原字符串取出子字符串并返回，不改变原字符串。第一个参数是子字符串的开始位置，第二个参数是子字符串的长度。如果第一个参数是负数，表示倒数计算的字符位置。如果第二个参数是负数，将被自动转为0，因此会返回空字符串。</span></span><br><span class="line">s.indexOf(s)   <span class="comment">//返回给定元素在字符串中第一次出现的位置，如果没有出现则返回-1。可以接受第二个参数，表示搜索的开始位置 </span></span><br><span class="line">s.lastIndexOf()  <span class="comment">//返回给定元素在字符串中最后一次出现的位置，如果没有出现则返回-1。</span></span><br><span class="line">s.trim()  <span class="comment">//用于去除字符串两端的空格，返回一个新字符串</span></span><br><span class="line">s.toLowerCase()  <span class="comment">//用于将一个字符串全部转为小写,返回一个新字符串，不改变原字符串。</span></span><br><span class="line">s.toUpperCase()  <span class="comment">//全部转为大写</span></span><br><span class="line">s.localeCompare(s2)  <span class="comment">//用于比较两个字符串。它返回一个整数，如果小于0，表示第一个字符串小于第二个字符串；如果等于0，表示两者相等；如果大于0，表示第一个字符串大于第二个字符串。</span></span><br><span class="line">s.match(regexp)   <span class="comment">//用于确定原字符串是否匹配某个子字符串，返回一个数组，成员为匹配的第一个字符串。如果没有找到匹配，则返回null。</span></span><br><span class="line">s.search()  <span class="comment">//返回值为匹配的第一个位置。如果没有找到匹配，则返回-1。</span></span><br><span class="line">s.replace(oldValue,newValue)  <span class="comment">//用于替换匹配的子字符串，一般情况下只替换第一个匹配（除非使用带有g修饰符的正则表达式）。</span></span><br><span class="line">s.split()  <span class="comment">//按照给定规则分割字符串，返回一个由分割出来的子字符串组成的数组。还可传入第二个参数，决定了返回数组的成员数。</span></span><br></pre></td></tr></table></figure>
<p><strong>3.5 Math对象</strong></p>
<p><strong>（1）属性</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.E：常数e。  </span><br><span class="line"><span class="built_in">Math</span>.LN2：<span class="number">2</span>的自然对数。  </span><br><span class="line"><span class="built_in">Math</span>.LN10：<span class="number">10</span>的自然对数。  </span><br><span class="line"><span class="built_in">Math</span>.LOG2E：以<span class="number">2</span>为底的e的对数。  </span><br><span class="line"><span class="built_in">Math</span>.LOG10E：以<span class="number">10</span>为底的e的对数。  </span><br><span class="line"><span class="built_in">Math</span>.PI：常数Pi。  </span><br><span class="line"><span class="built_in">Math</span>.SQRT1_2：<span class="number">0.5</span>的平方根。  </span><br><span class="line"><span class="built_in">Math</span>.SQRT2：<span class="number">2</span>的平方根。</span><br></pre></td></tr></table></figure>
<p><strong>（2）数学方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.abs()：返回参数的绝对值  </span><br><span class="line"><span class="built_in">Math</span>.ceil()：向上取整，接受一个参数，返回大于该参数的最小整数。 </span><br><span class="line"><span class="built_in">Math</span>.floor()：向下取整  </span><br><span class="line"><span class="built_in">Math</span>.max(n,n1,...)：可接受多个参数，返回最大值  </span><br><span class="line"><span class="built_in">Math</span>.min(n,n1,..)：可接受多个参数，返回最小值  </span><br><span class="line"><span class="built_in">Math</span>.pow(n,e)：指数运算, 返回以第一个参数为底数、第二个参数为幂的指数值。 </span><br><span class="line"><span class="built_in">Math</span>.sqrt()：返回参数值的平方根。如果参数是一个负值，则返回<span class="literal">NaN</span>。  </span><br><span class="line"><span class="built_in">Math</span>.log()：返回以e为底的自然对数值。</span><br><span class="line"><span class="built_in">Math</span>.exp()：返回e的指数，也就是常数e的参数次方。</span><br><span class="line"><span class="built_in">Math</span>.round()：四舍五入  </span><br><span class="line"><span class="built_in">Math</span>.random()：返回<span class="number">0</span>到<span class="number">1</span>之间的一个伪随机数，可能等于<span class="number">0</span>，但是一定小于<span class="number">1</span>。</span><br></pre></td></tr></table></figure>
<p><strong>（3）三角函数方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">Math</span>.sin()：返回参数的正弦  </span><br><span class="line"><span class="built_in">Math</span>.cos()：返回参数的余弦  </span><br><span class="line"><span class="built_in">Math</span>.tan()：返回参数的正切  </span><br><span class="line"><span class="built_in">Math</span>.asin()：返回参数的反正弦（弧度值）  </span><br><span class="line"><span class="built_in">Math</span>.acos()：返回参数的反余弦（弧度值）  </span><br><span class="line"><span class="built_in">Math</span>.atan()：返回参数的反正切（弧度值）</span><br></pre></td></tr></table></figure>
<p><strong>3.6 JSON对象</strong></p>
<p><strong>（1）方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">JSON</span>.stringify()   </span><br><span class="line"><span class="comment">//用于将一个值转为字符串。该字符串应该符合JSON格式，并且可以被JSON.parse方法还原。</span></span><br><span class="line"><span class="comment">//（JSON.stringify(obj, selectedProperties)）还可以接受一个数组，作为第二个参数，指定需要转成字符串的属性。</span></span><br><span class="line"><span class="comment">//还可以接受第三个参数，用于增加返回的JSON字符串的可读性。如果是数字，表示每个属性前面添加的空格（最多不超过10个）；如果是字符串（不超过10个字符），则该字符串会添加在每行前面。</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">JSON</span>.parse()   <span class="comment">//用于将JSON字符串转化成对象。</span></span><br></pre></td></tr></table></figure>
<p><strong>3.7 console对象</strong></p>
<p><strong>（1）方法</strong></p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(text,text2,...)   <span class="comment">//用于在console窗口输出信息。它可以接受多个参数，将它们的结果连接起来输出。如果第一个参数是格式字符串（使用了格式占位符），console.log方法将依次用后面的参数替换占位符，然后再进行输出。</span></span><br><span class="line"><span class="built_in">console</span>.info()   <span class="comment">//在console窗口输出信息，同时，会在输出信息的前面，加上一个蓝色图标。</span></span><br><span class="line"><span class="built_in">console</span>.debug()  <span class="comment">//在console窗口输出信息，同时，会在输出信息的前面，加上一个蓝色图标。</span></span><br><span class="line"><span class="built_in">console</span>.warn()  <span class="comment">//输出信息时，在最前面加一个黄色三角，表示警告；</span></span><br><span class="line"><span class="built_in">console</span>.error()  <span class="comment">//输出信息时，在最前面加一个红色的叉，表示出错，同时会显示错误发生的堆栈</span></span><br><span class="line"><span class="built_in">console</span>.table()  <span class="comment">//可以将复合类型的数据转为表格显示。</span></span><br><span class="line"><span class="built_in">console</span>.count()  <span class="comment">//用于计数，输出它被调用了多少次。</span></span><br><span class="line"><span class="built_in">console</span>.dir()    <span class="comment">//用来对一个对象进行检查（inspect），并以易于阅读和打印的格式显示。</span></span><br><span class="line"><span class="built_in">console</span>.dirxml()  <span class="comment">//用于以目录树的形式，显示DOM节点。</span></span><br><span class="line"><span class="built_in">console</span>.assert()  <span class="comment">//接受两个参数，第一个参数是表达式，第二个参数是字符串。只有当第一个参数为false，才会输出第二个参数，否则不会有任何结果。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//这两个方法用于计时，可以算出一个操作所花费的准确时间。</span></span><br><span class="line"><span class="built_in">console</span>.time()</span><br><span class="line"><span class="built_in">console</span>.timeEnd()</span><br><span class="line"><span class="comment">//time方法表示计时开始，timeEnd方法表示计时结束。它们的参数是计时器的名称。调用timeEnd方法之后，console窗口会显示“计时器名称: 所耗费的时间”。</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.profile()  <span class="comment">//用来新建一个性能测试器（profile），它的参数是性能测试器的名字。</span></span><br><span class="line"><span class="built_in">console</span>.profileEnd()  <span class="comment">//用来结束正在运行的性能测试器。</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.group()</span><br><span class="line"><span class="built_in">console</span>.groupend()</span><br><span class="line"><span class="comment">//上面这两个方法用于将显示的信息分组。它只在输出大量信息时有用，分在一组的信息，可以用鼠标折叠/展开。</span></span><br><span class="line"><span class="built_in">console</span>.groupCollapsed()  <span class="comment">//用于将显示的信息分组，该组的内容，在第一次显示时是收起的（collapsed），而不是展开的。</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.trace()  <span class="comment">//显示当前执行的代码在堆栈中的调用路径。</span></span><br><span class="line"><span class="built_in">console</span>.clear()  <span class="comment">//用于清除当前控制台的所有输出，将光标回置到第一行。</span></span><br></pre></td></tr></table></figure>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2017/11/20/react-study-Immutable/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2018/01/12/echart/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
